<template>
	<view class="make" @touchmove.stop.prevent @tap.stop="hidePopup" v-if="myshow"
		:style="{backgroundColor:client != '100%'?'rgba(0,0,0,0.3)':'rgba(0,0,0,0)'}">
		<view class="popup"
			:style="{transform:client != '100%'?'translateY('+client+'px)':'translateY(100%)',transition:!isTouch?'0.4s ease,transform 0.2s ease':'0.4s ease,transform 0s ease'}">
			<view class="box" @tap.stop @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend">
				<view class="title">
					<slot name="title">
					</slot>
				</view>
				<view class="btns">
					<view @tap="tap('cancel')">
						<slot name="cancel">
							取消
						</slot>
					</view>
					<view style="margin-left: 30rpx;" @tap="tap('confirm')">
						<slot name="confirm">
							确定
						</slot>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				myshow: false,
				clientY: 0,
				client: '100%',
				ismake: false,
				defaultNum: 0,
				isTouch: false
			};
		},
		props: {
			show: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			show() {
				if (this.show) {
					this.myshow = true
					setTimeout(() => {

						this.client = 0
						this.defaultNum = 0
					}, 100)
				} else {
					this.hidePopup()

				}
			}
		},
		methods: {

			touchstart({
				touches
			}) {
				this.isTouch = true
				this.clientY = touches[0].clientY
				return
			},
			touchmove({
				touches
			}) {
				if (this.defaultNum == 0) {
					let num = (touches[0].clientY - this.clientY) + 0
					if (num > 0) {
						this.client = num
					}

				}
				return
			},
			touchend(end) {
				this.isTouch = false

				if (this.defaultNum == 0) {
					if (this.client >= 50) {
						this.hidePopup()
					} else {

						this.client = 0
						this.defaultNum = 0
					}
				}

				return
			},
			tap(type) {
				this.$emit('change', type)
				this.$emit('update:show', false)
			},
			hidePopup() {
				this.client = '100%'
				setTimeout(() => {
					this.$emit('update:show', false)
					this.myshow = false
				}, 200)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.make {
		position: fixed;
		width: 100%;
		height: 100%;
		bottom: 0;
		right: 0;
		background-color: rgba(0, 0, 0, 1);
		transition: 0.2s;
		// background: linear-gradient(0deg, rgba(0, 0, 0, 0.2) 50%, rgba(0, 0, 0, 0) 90%);
		z-index: 9999;

		.popup {
			position: absolute;
			bottom: 0;
			height: 100%;
			width: 100%;
			display: flex;
			z-index: 9999;
			flex-direction: column;
			border-radius: 50rpx 50rpx 0 0;
			overflow: hidden;
			justify-content: flex-end;

			.box {
				margin: 60rpx 30rpx;

				border-radius: 30rpx;
				background-color: #fff;
				display: flex;
				flex-direction: column;

				.title {
					display: flex;
					justify-content: center;
					padding: 30rpx;
					font-size: 16px;
					font-weight: bold;
				}

				.btns {
					display: flex;
					padding: 30rpx;

					view {
						flex: 1;
						text-align: center;
						border-radius: 20rpx;
						padding: 25rpx 30rpx;
						background-color: #F9F9F9;
						color: #0f7ffc;
						font-weight: bold;

						&:active {
							background-color: #f2f2f2;
						}
					}
				}
			}

		}
	}
</style>
